package com.cqc.greendao05.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cqc.greendao05.R;
import com.cqc.greendao05.bean.PersonInfo;

import java.util.List;

/**
 * Created by ${cqc} on 2017/1/3.
 */

public class MyAdapter extends RecyclerView.Adapter {

    private List<PersonInfo> list;

    public MyAdapter(List<PersonInfo> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        MyViewHolder holder = (MyViewHolder) viewHolder;
        PersonInfo info = list.get(position);
        holder.tv1.setText("id:" + info.getId());
        holder.tv2.setText("id:" + info.getName());
        holder.tv3.setText("id:" + info.getAge());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tv1;
        TextView tv2;
        TextView tv3;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv1 = (TextView) itemView.findViewById(R.id.tv1);
            tv2 = (TextView) itemView.findViewById(R.id.tv2);
            tv3 = (TextView) itemView.findViewById(R.id.tv3);
        }
    }
}
